package cn.net.xyan.easy.webapp.base.entity;

import cn.net.xyan.easy.spring.jpa.utils.sequence.TableSequenceGenerator;
import org.hibernate.annotations.*;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.List;

/**
 * Created by xiashenpin on 16/1/23.
 */
@Entity
@Table(name = "t_sys_permission")
@Inheritance(strategy= InheritanceType.JOINED)
@DiscriminatorColumn(name="type",discriminatorType = DiscriminatorType.STRING)
public class Permission {
    String sequence;
    String permission;
    String describe;
    List<SystemUser> users;
    List<PermissionGroup> groups;

    public Permission(){

    }

    public Permission(String permission){
        this.permission = permission;
    }

    @Id
    @Column(name = "id",unique = true,updatable = false,nullable = false,length = 32)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = Permission_.SEQUENCE_)
    @GenericGenerator(name = Permission_.SEQUENCE_,
            strategy = TableSequenceGenerator.STRATEGY,
            parameters = {
                   // @org.hibernate.annotations.Parameter(name = org.hibernate.id.enhanced.TableGenerator.SEGMENT_VALUE_PARAM, value = Permission_.SEQUENCE_),
                    @org.hibernate.annotations.Parameter(name = "format", value = "P0000000")
                    //@org.hibernate.annotations.Parameter(name = "formatClass", value = ArchiveIDFormat.FormatClass)
            })
    public String getSequence() {
        return sequence;
    }

    public void setSequence(String sequence) {
        this.sequence = sequence;
    }

    @Column(name = "permission_name",nullable = false,unique = true)
    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public String getDescribe() {
        return describe;
    }

    public void setDescribe(String describe) {
        this.describe = describe;
    }

    @ManyToMany(mappedBy = "permissions")
    public List<SystemUser> getUsers() {
        return users;
    }

    public void setUsers(List<SystemUser> users) {
        this.users = users;
    }

    @ManyToMany(mappedBy = "permissions")
    public List<PermissionGroup> getGroups() {
        return groups;
    }

    public void setGroups(List<PermissionGroup> groups) {
        this.groups = groups;
    }
}
